package com.liesheng.haylou.ui.main.home;


import android.animation.ValueAnimator;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.SpinnerAdapter;


import com.liesheng.haylou.R;
import com.liesheng.haylou.app.HyApplication;
import com.liesheng.haylou.base.BaseFragment;
import com.liesheng.haylou.base.BaseFunActivity;
import com.liesheng.haylou.base.BaseVm;
import com.liesheng.haylou.bean.UserUpdateBean;
import com.liesheng.haylou.common.GlideHelper;
import com.liesheng.haylou.databinding.FragmentHomeBinding;
import com.liesheng.haylou.ui.Login.LoginActivity;
import com.liesheng.haylou.ui.main.card.CardManagementActivity;
import com.liesheng.haylou.ui.personal.PersonalCenterActivity;
import com.liesheng.haylou.utils.sp.SpUtil;

import androidx.databinding.DataBindingUtil;


/**
 * Date:${DATA}
 * Author ${ZhangZhiQiang}
 * Description
 */
public class HomeFragment extends BaseFragment<FragmentHomeBinding, BaseVm> {
    private UserUpdateBean userUpdateBean;

    @Override
    protected FragmentHomeBinding getDataBinding() {
        dataBinding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout.fragment_home, null, false);
        return dataBinding;

    }

    @Override
    public BaseVm getViewModel() {
        return null;
    }

    protected void initData() {
        showEmptyLayout(false);
        setHeadLayoutViesible(false);
        setAnimation(dataBinding.progressBar, 100);
        dataBinding.ivLoginPhoto.setVisibility(View.VISIBLE);
        dataBinding.ivLoginPhoto.setBackgroundResource(R.drawable.ico_avatar_unknown);
        dataBinding.tvNickName.setVisibility(View.VISIBLE);
        dataBinding.tvNickName.setText(SpUtil.getNickName());
        GlideHelper.loadCicleImage(dataBinding.ivLoginPhoto, "http://ls-app-file.haylou.com/" + SpUtil.getAvatar());

    }

    @Override
    public void onClickView(View view) {
        switch (view.getId()) {
            case R.id.ivLoginPhoto:
                PersonalCenterActivity.startBy((BaseFunActivity) getActivity());
                break;
            case R.id.tvLogin:
                LoginActivity.startBy((BaseFunActivity) getActivity());
                break;
            case R.id.progressBar:

                break;
            case R.id.reRight:
                CardManagementActivity.startBy((BaseFunActivity) getActivity());
                break;

        }
    }

    private void setAnimation(final ProgressBar view, final int mProgressBar) {
        ValueAnimator animator = ValueAnimator.ofInt(0, mProgressBar).setDuration(5000);

        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                view.setProgress((int) valueAnimator.getAnimatedValue());
            }
        });
        animator.start();
    }

    /**
     * 方法必须重写
     * map的生命周期方法
     */
    @Override
    public void onResume() {
        super.onResume();
    }

    /**
     * 方法必须重写
     * map的生命周期方法
     */
    @Override
    public void onPause() {
        super.onPause();
    }


    /**
     * 方法必须重写
     * map的生命周期方法
     */
    @Override
    public void onDestroy() {
        super.onDestroy();

    }

}
